﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace CPPEI.Coolzon.UI
{
    public class AbsoluteLayout : Layout
    {
        private Canvas _panel;
        private PartFrame _centerFrame;

        public override void AttachToPart(ILayoutContainer part)
        {
            _panel = new Canvas();
            _panel.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            _panel.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            //_panel.Background = new SolidColorBrush(Colors.Gray);
            part.SetLayout(this);
        }

        /// <summary>
        /// x,y,w,h
        /// </summary>
        /// <param name="position"></param>
        /// <param name="frame"></param>
        protected override void OnAddFrame(string position, PartFrame frame)
        {
            try
            {
                string[] posArr = position.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                double x = Convert.ToDouble(posArr[0]);
                double y = Convert.ToDouble(posArr[1]);
                Canvas.SetLeft(frame, x);
                Canvas.SetTop(frame, y);
            }
            catch
            {
            }
            this._panel.Children.Add(frame);
        }

        public override void AddPart(Point position, Part part)
        {
            this._panel.Children.Add(part);
            Canvas.SetLeft(part, position.X);
            Canvas.SetTop(part, position.Y);
        }

        public override object GetUIContent()
        {
            return _panel;
        }
    }
}
